/**
 * JAVACC DEMO 1.0
 * @copy right dwusoft company All rights reserved. 
 * @Package com.apache.bid.service.plugins  
 */
package com.apache.bid.service.plugins;

import java.util.List;

import org.apache.log4j.Logger;

import com.apache.api.manager.PluginConnector;
import com.apache.api.vo.ParamsVo;
import com.apache.api.vo.ResultEntity;
import com.apache.bid.entity.BidItemPrice;
import com.apache.cache.util.Validator;
import com.apache.database.db.IDao;
import com.apache.database.model.MethodParam;
import com.apache.database.model.Page;

/**
 * description:  查询itemId列表
 * @author mhguo 创建时间：2016-4-16  
 * 
 */
public class BidItemIdListPlugin implements PluginConnector {

	private IDao bidItemPriceDao;
	private Logger logger = Logger.getLogger(BidItemIdListPlugin.class);

	/**
	 * TODO 简单描述该方法的实现功能（可选）.  
	 * @see com.zbxsoft.api.manager.PluginConnector#execute(com.zbxsoft.api.vo.ParamsVo)  
	 */
	@Override
	public Object execute(ParamsVo vo) throws Exception {
		ResultEntity result = new ResultEntity();
		try {
			result.setResult("true");
			String userName = String.valueOf(vo.getParams("userName"));
			if (Validator.isNull(userName)) {
				result.setResult("false");
				result.setMessage("查询条件为空！");
				return result;
			}

			MethodParam param = new MethodParam("ByUserNameForItemIds", "", "", BidItemPrice.class.getName());
			param.setResultCache(false);
			param.setParams("userName", userName);

			int pageSize = Integer.valueOf(Validator.getDefaultStr(String.valueOf(vo.getParams("pageSize")), "0"));
			int pageIndex = Integer.valueOf(Validator.getDefaultStr(String.valueOf(vo.getParams("pageIndex")), "0"));
			param.setResultCache(false);

			if (pageSize == 0 && pageIndex == 0) {
				List list = bidItemPriceDao.select(param);
				result.setEntity(list);
			} else {
				param.setPageIndex(pageIndex);
				param.setPageSize(pageSize);
				Page page = bidItemPriceDao.pageSelect(param);
				result.setEntity(page);
			}
		} catch (Exception e) {
			result.setResult("false");
			logger.error("itemId列表查询失败 ", e);
			result.setMessage("itemId列表查询失败！");
		}
		return result;
	}

	public void setBidItemPriceDao(IDao bidItemPriceDao) {
		this.bidItemPriceDao = bidItemPriceDao;
	}

}
